package com.xinghou.platform.server.api.base;

import com.xinghou.platform.server.api.common.ResponseTools;
import com.xinghou.platform.util.exception.ServiceException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by qin11gshengzheng on 15/11/20.i
 */
public class ExceptionHandler implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        if (e instanceof ServiceException) {
           String response= ResponseTools.get().response( e);
            ResponseTools.get().responseResult(httpServletResponse,response);
        }

        return null;
    }
}
